#ifndef CANNON_H
#define CANNON_H

#include "ActorEntity.h"

#include "../../Util/Direction2D.h"
#include "../../Model/Model.h"
#include "../../WrappedContainers/LinkedList.h"

class Cannon : public ActorEntity {
public:
	static LinkedList<Cannon*> destoyed;

protected:
	static const float maxFirepower;
	static const float minFirepower;

	float hp;
	float firepower;

	static const float firepowerStep;
	static const float rotationForce;

	static const float cannonDensity;
	static const float barsDensity;

	static const float damping;
	static const float jointDamping;

	NxActor* aGroundBars;
	NxActor* aMiddleBars;
	NxActor* aCannon;

	NxRevoluteJoint* jBars;
	NxRevoluteJoint* jCannon;

	static const float modelScale;

	static NxVec3 groundBarsOffset;
	static NxVec3 middleBarsOffset;
	static NxVec3 cannonOffset;

	static Model modelGroundBars;
	static Model modelMiddleBars;
	static Model modelCannon;

	static NxBodyDesc bdGroundBars;
	static NxBodyDesc bdMiddleBars;
	static NxBodyDesc bdCannon;

	static NxActorDesc adGroundBars;
	static NxActorDesc adMiddleBars;
	static NxActorDesc adCannon;

	static NxSpringDesc spingdBars;
	static NxSpringDesc spingdCannon;

	static NxJointLimitPairDesc jlpdBars;
	static NxJointLimitPairDesc jlpdCannon;

public:
	static void Load();

	Cannon(const NxVec3& pos, const NxVec3& orientation);
	virtual ~Cannon();

	virtual inline ACTOR_ENTITY_TYPE GetType() const { return AET_CANNON;	}

	inline float GetHitpoints() const { return hp; }
	inline float GetFirepower() const { return firepower; }
	inline bool IsDestroyed() { return hp <= 0; }

	NxVec3 GetPosition();
	NxVec3 GetGroundPosition();
	NxVec3 GetDirection();

	void Rotate(DIRECTION_2D direction);
	void Rotate(DIRECTION_2D direction, float force);
	void TakeDamage(float force);
	void Fire();
	void IncreaseFirepower();
	void DecreaseFirepower();
	void ChangeFirepowerBy(float v);

	virtual void Draw();
};

#endif //CANNON_H
